<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>看密码</title>
    <style>
        *{
            padding: 0;
            margin: 0;
        }

        .box{
            width: 400px;
            height: 30px;
            border: 1px solid red;
            margin: 100px auto;
        }
        .box input{
            padding-left: 10px;
            border: 0;
            width: 250px;
            height: 30px;
        }
        .box button{
            border: 0;
            width: 100px;
            height: 100%;

        }
    </style>
</head>
<body>
    <div class="box">
        <input type="password" id="eye">
        <button id="btn">按一下</button>
    </div>
    
    <script>
        var flag = 1;
        var pw = document.getElementById('eye');
        var btn = document.getElementById('btn');
        btn.onclick = function () {
            if(flag == 1){
                console.log('进来了1');
                pw.type = 'text';
                flag = 0;
            }
            else{
                console.log('进来了0');
                pw.type = 'password';
                flag = 1;
            }
        }
    </script>
</body>
</html>